package com.mozz.finally_work.servlet;

import com.mozz.finally_work.dao.BlogDao;
import com.mozz.finally_work.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/*删除博客servlet*/
@WebServlet(name = "DeleteBlogServlet", value = "/DeleteBlogServlet")
public class DeleteBlogServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*获取参数*/
        String blogId = request.getParameter("blogId");
        String userId = request.getParameter("userId");
        /*调用dao*/
        SqlSession session = MybatisUtils.getSession();
        BlogDao dao = session.getMapper(BlogDao.class);
        Integer result = dao.deleteBlog(blogId);
        session.commit();
        session.close();
        response.sendRedirect("UserHomeServlet?userId="+userId);
    }
}
